/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aktor;

import java.sql.*;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author WIN7
 */
public class ChattingPasien {
    
    private String Pesan;
    private String Inbox;
    private String Id_penerima;
    private String Id_pengirim;
    private String outbox;

    /**
     * @return the Pesan
     */
    public String getPesan() {
        return Pesan;
    }

    /**
     * @param Pesan the Pesan to set
     */
    public void setPesan(String Pesan) {
        this.Pesan = Pesan;
    }

    /**
     * @return the Inbox
     */
    public String getInbox() {
        return Inbox;
    }

    /**
     * @param Inbox the Inbox to set
     */
    public void setInbox(String Inbox) {
        this.Inbox = Inbox;
    }

    /**
     * @return the outbox
     */
    public String getOutbox() {
        return outbox;
    }

    /**
     * @param outbox the outbox to set
     */
    public void setOutbox(String outbox) {
        this.outbox = outbox;
    }
    
    public void insertChat() throws SQLException {
        Connection con = DataBaseConnection.getDBConnection();
        
        String SQL = "insert into chatting_pasien (id_pengirim, id_penerima, pesan) values (?,?,?)";
        
        PreparedStatement ps = con.prepareStatement(SQL);
        
        ps.setString(1, this.Id_pengirim);
        ps.setString(2, this.Id_penerima);
        ps.setString(3, this.Pesan);
        
        int x = ps.executeUpdate();
        ps.close();
        con.close();
    }

    /**
     * @return the Id_penerima
     */
    public String getId_penerima() {
        return Id_penerima;
    }

    /**
     * @param Id_penerima the Id_penerima to set
     */
    public void setId_penerima(String Id_penerima) {
        this.Id_penerima = Id_penerima;
    }

    /**
     * @return the Id_pengirim
     */
    public String getId_pengirim() {
        return Id_pengirim;
    }

    /**
     * @param Id_pengirim the Id_pengirim to set
     */
    public void setId_pengirim(String Id_pengirim) {
        this.Id_pengirim = Id_pengirim;
    }
    
    public ArrayList<ChattingPasien> getInbox(String id) {
        ArrayList<ChattingPasien> inbox = new ArrayList<ChattingPasien>();
        try {
            Connection con = DataBaseConnection.getDBConnection();
            
            String SQL = "select pesan, id_pengirim from chatting_konsultan where id_penerima = '" + id + "'";
            
            Statement ps = con.createStatement();
            
            ResultSet rs = ps.executeQuery(SQL);
            while (rs.next()) {
                ChattingPasien chatP = new ChattingPasien();
                chatP.setPesan(rs.getString(1));
                chatP.setId_pengirim(rs.getString(2));
                inbox.add(chatP);
            }
            ps.close();
            con.close();
        } catch (SQLException ex) {
            Logger.getLogger(ChattingPasien.class.getName()).log(Level.SEVERE, null, ex);
        }
        return inbox;
    }
    
    public ArrayList<String> getOutbox(String id) {
        ArrayList<String> outbox = new ArrayList<String>();
        try {
            Connection con = DataBaseConnection.getDBConnection();
            
            String SQL = "select pesan from chatting_pasien where id_pengirim = '" + id + "'";
            
            Statement ps = con.createStatement();
            
            ResultSet rs = ps.executeQuery(SQL);
            while (rs.next()) {
                outbox.add(rs.getString(1));
            }
            ps.close();
            con.close();
        } catch (SQLException ex) {
            Logger.getLogger(ChattingPasien.class.getName()).log(Level.SEVERE, null, ex);
        }
        return outbox;
    }
}
